package com.zmx.job.execute.handler.b2c.order;

import com.zmx.core.handler.annotation.MallJob;
import com.zmx.job.execute.handler.b2c.order.entity.B2COrder;
import com.zmx.job.execute.handler.b2c.order.repository.B2COrderRepository;
import com.zmx.job.execute.handler.b2c.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description: 超时未支付订单定时取消任务
 * @ClassName: OverduePaymentCancelOrderJob
 * @Author zhaomxr
 * @Date 2022-01-04 16:37
 */
@Slf4j
@Component
public class OverduePaymentCancelOrderJob {

    @Autowired
    private OrderService orderService;
    @Autowired
    private B2COrderRepository b2COrderRepository;

    @MallJob(value = "cancelOrderJob")
    public void cancelOrderJob() throws InterruptedException {
        log.info("开始执行 取消30分钟未支付订单");
        long start = System.currentTimeMillis();
        //所有待取消订单
        List<B2COrder> orders = b2COrderRepository.getOverdueCancelOrder();

        log.info("待取消订单数：{}", orders.size());
        for (B2COrder b2COrder : orders) {
            orderService.overdueCancelOrder(b2COrder);
        }

        log.info("执行完成 用时：{} 毫秒", System.currentTimeMillis() - start);
    }
}
